package DBLayer;

import DBLayer.Interfaces.IContainer;
import ModelLayer.Supplier;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DBSupplier extends DatabaseAccess implements IContainer<Supplier>
{
    public DBSupplier()
    {
        super();
    }

    public Supplier getObject(int SupplierID)
    {
        String query = "Select SupplierID as ID, RoleID From Supplier Where Supplier.SupplierID = " + SupplierID;
        GenericModelBinder<Supplier> modelBinder = new GenericModelBinder<Supplier>(Supplier.class);

        try
        {
            return modelBinder.BindModel(ExecuteQuery(query));
        }
        catch (SQLException ex)
        {
            Logger.getLogger(DBSupplier.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex)
        {
            Logger.getLogger(DBSupplier.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex)
        {
            Logger.getLogger(DBSupplier.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }

    public ArrayList<Supplier> getObjects()
    {
        String query = "Select SupplierID as ID, RoleID From Supplier";
        GenericModelBinder<Supplier> modelBinder = new GenericModelBinder<Supplier>(Supplier.class);

        try
        {
            return modelBinder.BindModels(ExecuteQuery(query));
        }
        catch (SQLException ex)
        {
            Logger.getLogger(DBSupplier.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex)
        {
            Logger.getLogger(DBSupplier.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex)
        {
            Logger.getLogger(DBSupplier.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }

    public Supplier getSupplierByActorID(int actorID)
    {
        String query = "Select SupplierID as ID, [Role].RoleID, ActorID From Supplier, [Role] Where Role.RoleID = Supplier.RoleID and Role.ActorID = " + actorID;
        GenericModelBinder<Supplier> modelBinder = new GenericModelBinder<Supplier>(Supplier.class);

        try
        {
            return modelBinder.BindModel(ExecuteQuery(query));
        }
        catch (SQLException ex)
        {
            Logger.getLogger(DBSupplier.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex)
        {
            Logger.getLogger(DBSupplier.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex)
        {
            Logger.getLogger(DBSupplier.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }

    public boolean SaveObject(Supplier object)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean DeleteObject(Supplier object)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean UpdateObject(Supplier object)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
